//
//  LJFDestinationController.m
//  SevenZhou
//
//  Created by qianfeng on 15/9/14.
//  Copyright (c) 2015年 ljf. All rights reserved.
//

#import "LJFDestinationController.h"
#import "LJFLeftController.h"
#import "LJFRightController.h"
#import "Masonry.h"
#import "LJFHttpManager.h"
#import "LJFContinentModel.h"
#import "MBProgressHUD.h"
#import "LJFCustomController.h"
#import "LJFHomeController.h"

@interface LJFDestinationController ()
{
    NSMutableArray *_dataArr;
    
    MBProgressHUD *_HUD;
}

@end

@implementation LJFDestinationController

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        _dataArr = [[NSMutableArray alloc] init];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self showProgress];
    
    [self loadDataFromNet];
}

- (void)showProgress
{
    _HUD = [[MBProgressHUD alloc] initWithView:self.view];
    _HUD.labelText = @"正在努力加载中";
    
    [self.view addSubview:_HUD];
    
    [_HUD show:YES];
    
}

#pragma mark - 从网络加载数据

- (void)loadDataFromNet
{
    LJFHttpManager *manager = [LJFHttpManager shareInstance];
    
    [manager getDataFromNetWithUrl:URL_SevenZhouData AndParameterStr:@"" success:^(id responseObj)
    {
        NSDictionary *dict = responseObj;
        
        for (NSDictionary *dic in dict[@"data"])
        {
            LJFContinentModel *model = [[LJFContinentModel alloc] initWithDictionary:dic];
            
            [_dataArr addObject:model];
            
            [self loadLeftAndRightController];
        }
        
        [_HUD hide:YES];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"SevenZhou" object:_dataArr userInfo:nil];
        
    } failure:^(NSError *error)
    {
       
        NSLog(@"error == %@",error);
        
    }];
}

#pragma mark - 创建左右抽屉

- (void)loadLeftAndRightController
{

    LJFLeftController *left = [self.storyboard instantiateViewControllerWithIdentifier:@"LJFLeftController"];
    LJFRightController *right = [self.storyboard instantiateViewControllerWithIdentifier:@"LJFRightController"];
    
    
    [self addChildViewController:left];
    [self addChildViewController:right];
    
    [self.view addSubview:left.view];
    [self.view addSubview:right.view];
    
    //手写代码自动布局
    [left.view mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.equalTo(self.view.mas_top).offset(64);
         make.left.equalTo(self.view.mas_left).offset(0);
         make.bottom.equalTo(self.view.mas_bottom).offset(-49);
         make.right.equalTo(self.view.mas_right).offset(0);
     }];
    
    [right.view mas_makeConstraints:^(MASConstraintMaker *make)
     {
         make.top.equalTo(self.view.mas_top).offset(64);
         make.left.equalTo(self.view.mas_left).offset(80);
         make.bottom.equalTo(self.view.mas_bottom).offset(-49);
         make.right.equalTo(self.view.mas_right).offset(0);
     }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
